#ifndef MSERIALTHREAD_H
#define MSERIALTHREAD_H

#include "win_qextserialport.h"
#include <Windows.h>
#include <MMSystem.h>
#include "MBaseSerialThread.h"

#pragma comment(lib, "winmm.lib")

enum ESerialSettingsType{
    Serial_Name,
    Serial_BaudRate,
    Serial_DateBits,
    Serial_StopBits,
    Serial_Parity,
    Serial_Flow
};

#ifndef SERIALCONFIG
#define SERIALCONFIG
struct SERIAL_CONFIG
{
    BaudRateType serialBaudrate;
    DataBitsType serialDatabits;
    StopBitsType serialStopbits;
    ParityType serialParity;
    FlowType serialFlow;
};
#endif


class MSerialThread: public MBaseSerialThread
{
    Q_OBJECT

public:
    explicit MSerialThread(int id);//
    ~MSerialThread();

    virtual void setup(QHash<QString, QString> config);//配置参数

    virtual int initSerial(QVariant channel,QVariantVector subdivision = QVariantVector());

    virtual bool isOpen();

    virtual int  write(QByteArray &ucDataArray, int id = 0);// 写数据

    virtual void close();

signals:

protected:
    SERIAL_CONFIG   m_serialConfig;//串行接口配置

    virtual void run();

    Win_QextSerialPort*     m_pSerial;// 定义串口类
    PortSettings            portSettings;//串口配置
};

#endif // MSERIALTHREAD_H
